#include "vpframe.h"

int VpFrame::serial() const
{
    return m_serial;
}

void VpFrame::setSerial(int newSerial)
{
    m_serial = newSerial;
}

VpFrame::VpFrame()
{
    m_frame    = av_frame_alloc();
    m_serial   = 0;
    m_pts      = 0;
    m_duration = 0;
}

VpFrame::~VpFrame()
{
    if(m_frame)
        av_frame_free(&m_frame);
}

VpFrame::VpFrame(const VpFrame &temp)
{
    m_frame = av_frame_alloc();
    if(temp.m_frame->pts != AV_NOPTS_VALUE) {
        av_frame_ref(m_frame, temp.m_frame);
        av_frame_copy_props(m_frame, temp.m_frame);
    }
    m_serial = temp.m_serial;
    m_pts = temp.m_pts;
}

VpFrame &VpFrame::operator=(const VpFrame &temp)
{
    if(m_frame)
        av_frame_free(&m_frame);
    lock_guard<mutex> lock(m_mutex);
    m_frame = av_frame_alloc();
    if(temp.m_frame->pts != AV_NOPTS_VALUE) {
        av_frame_ref(m_frame, temp.m_frame);
        av_frame_copy_props(m_frame, temp.m_frame);
    }
    m_serial = temp.serial();
    m_pts = temp.m_pts;
    return *this;
}
